
# =============================================================================
# PRQ Replication — Simplified, Single-Path, No-Conditionals
# =============================================================================
# - Follows the original analysis logic in prq_revise0713.R
# - Removes all `if (...)` branches
# - Uses one canonical data source and fixed outputs under ./0713/
# - Keeps formulas explicit and easy to read
# =============================================================================

# 0) Libraries ---------------------------------------------------------------
library(tidyverse)
library(lubridate)
library(ggplot2)
library(ggthemes)
library(haven)
library(rdrobust)
library(MASS)
library(broom)
library(ggrepel)
library(tibble)
library(readxl)
library(dplyr)
library(lmtest)
library(sandwich)
library(stargazer)
library(purrr)
library(hrbrthemes)
library(cowplot)

set.seed(202501)
dir.create("0713", showWarnings = FALSE, recursive = TRUE)

# 1) Data --------------------------------------------------------------------
# Follow original path and object name
load("russiaweibo.RData")   # must create object: rtweibonew
rtweibonew$date <- as.Date(rtweibonew$date)

# Sub-samples (fix WAR to use theme_ft_label)
RD  <- rtweibonew %>% dplyr::filter(theme_ft_label == "Rotted_democracy")
WH  <- rtweibonew %>% dplyr::filter(theme_ft_label == "West_hegemony")
RA  <- rtweibonew %>% dplyr::filter(theme_ft_label == "Russia_achievement")
RC  <- rtweibonew %>% dplyr::filter(theme_ft_label == "Russia_collaboration") 
CN  <- rtweibonew %>% dplyr::filter(theme_ft_label == "China_news")
SP  <- rtweibonew %>% dplyr::filter(theme_ft_label == "Soft_propaganda")
OC  <- rtweibonew %>% dplyr::filter(theme_ft_label == "Other_cues")
WAR <- rtweibonew %>% dplyr::filter(theme_ft_label == "War")

# Small helper for robust SE (keeps code DRY; no branching)
robust_se <- function(model) sqrt(diag(vcovHC(model, type = "HC1")))

# 2) Manuscript Table 1: Main Narratives (Soft_propaganda ref.) --------------
subnarrs <- c("Soft_propaganda","Rotted_democracy","West_hegemony",
              "Russia_collaboration","Russia_achievement")
df_main5 <- rtweibonew %>% dplyr::filter(theme_ft_label %in% subnarrs)
df_main5$theme_ft_label <- factor(df_main5$theme_ft_label, levels = subnarrs)

m1a <- lm(ln_shares   ~ theme_ft_label + treatment + length + unique + source + video + hashtag + daily_theme_source_count, data = df_main5)
m1b <- lm(ln_comments ~ theme_ft_label + treatment + length + unique + source + video + hashtag + daily_theme_source_count, data = df_main5)
m1c <- lm(ln_likes    ~ theme_ft_label + treatment + length + unique + source + video + hashtag + daily_theme_source_count, data = df_main5)

m1d <- lm(ln_shares   ~ theme_ft_label * treatment + length + unique + source + video + hashtag + daily_theme_source_count, data = df_main5)
m1e <- lm(ln_comments ~ theme_ft_label * treatment + length + unique + source + video + hashtag + daily_theme_source_count, data = df_main5)
m1f <- lm(ln_likes    ~ theme_ft_label * treatment + length + unique + source + video + hashtag + daily_theme_source_count, data = df_main5)

stargazer(m1a, m1b, m1c, m1d, m1e, m1f,
  type = "text",
  title = "Dependent variable: Public Engagement (Soft_propaganda as Reference)",
  se = list(robust_se(m1a), robust_se(m1b), robust_se(m1c), robust_se(m1d), robust_se(m1e), robust_se(m1f)),
  align = TRUE, star.cutoffs = c(0.05, 0.01, 0.001),
  out = "0713/table1_main5_soft.html"
)

# 3) Appendix Table 2: ALL Narratives (Soft_propaganda ref.) -----------------
all_levels <- c("Soft_propaganda","Rotted_democracy","West_hegemony","China_news",
                "Other_cues","War","Russia_collaboration","Russia_achievement")
df_all_soft <- rtweibonew
df_all_soft$theme_ft_label <- factor(df_all_soft$theme_ft_label, levels = all_levels)

m2a <- lm(ln_shares   ~ theme_ft_label + treatment + length + unique + source + video + hashtag + daily_theme_source_count, data = df_all_soft)
m2b <- lm(ln_comments ~ theme_ft_label + treatment + length + unique + source + video + hashtag + daily_theme_source_count, data = df_all_soft)
m2c <- lm(ln_likes    ~ theme_ft_label + treatment + length + unique + source + video + hashtag + daily_theme_source_count, data = df_all_soft)

m2d <- lm(ln_shares   ~ theme_ft_label * treatment + length + unique + source + video + hashtag + daily_theme_source_count, data = df_all_soft)
m2e <- lm(ln_comments ~ theme_ft_label * treatment + length + unique + source + video + hashtag + daily_theme_source_count, data = df_all_soft)
m2f <- lm(ln_likes    ~ theme_ft_label * treatment + length + unique + source + video + hashtag + daily_theme_source_count, data = df_all_soft)

stargazer(m2a, m2b, m2c, m2d, m2e, m2f,
  type = "text",
  title = "Dependent variable: Public Engagement (Soft_propaganda as Reference)",
  se = list(robust_se(m2a), robust_se(m2b), robust_se(m2c), robust_se(m2d), robust_se(m2e), robust_se(m2f)),
  align = TRUE, star.cutoffs = c(0.05, 0.01, 0.001),
  out = "0713/table2_all_soft.html"
)

# 4) Appendix Table 3: ALL Narratives (Other_cues ref.) ----------------------
all_levels_other <- c("Other_cues","Soft_propaganda","Rotted_democracy","West_hegemony",
                      "China_news","War","Russia_collaboration","Russia_achievement")
df_all_other <- rtweibonew
df_all_other$theme_ft_label <- factor(df_all_other$theme_ft_label, levels = all_levels_other)

m3a <- lm(ln_shares   ~ theme_ft_label + treatment + length + unique + source + video + hashtag + daily_theme_source_count, data = df_all_other)
m3b <- lm(ln_comments ~ theme_ft_label + treatment + length + unique + source + video + hashtag + daily_theme_source_count, data = df_all_other)
m3c <- lm(ln_likes    ~ theme_ft_label + treatment + length + unique + source + video + hashtag + daily_theme_source_count, data = df_all_other)

m3d <- lm(ln_shares   ~ theme_ft_label * treatment + length + unique + source + video + hashtag + daily_theme_source_count, data = df_all_other)
m3e <- lm(ln_comments ~ theme_ft_label * treatment + length + unique + source + video + hashtag + daily_theme_source_count, data = df_all_other)
m3f <- lm(ln_likes    ~ theme_ft_label * treatment + length + unique + source + video + hashtag + daily_theme_source_count, data = df_all_other)

stargazer(m3a, m3b, m3c, m3d, m3e, m3f,
  type = "text",
  title = "Dependent variable: Public Engagement (Other_cues as Reference)",
  se = list(robust_se(m3a), robust_se(m3b), robust_se(m3c), robust_se(m3d), robust_se(m3e), robust_se(m3f)),
  align = TRUE, star.cutoffs = c(0.05, 0.01, 0.001),
  out = "0713/table3_all_other.html"
)

# 5) Appendix Table 4: Pre-May 2022, Main Narratives (Soft ref.) -------------
df_prewar5 <- rtweibonew %>%
  dplyr::filter(date <= as.Date("2022-04-24") & theme_ft_label %in% subnarrs)
df_prewar5$theme_ft_label <- factor(df_prewar5$theme_ft_label, levels = subnarrs)

m4a <- lm(ln_shares   ~ theme_ft_label + treatment + length + unique + source + video + hashtag + daily_theme_source_count, data = df_prewar5)
m4b <- lm(ln_comments ~ theme_ft_label + treatment + length + unique + source + video + hashtag + daily_theme_source_count, data = df_prewar5)
m4c <- lm(ln_likes    ~ theme_ft_label + treatment + length + unique + source + video + hashtag + daily_theme_source_count, data = df_prewar5)

m4d <- lm(ln_shares   ~ theme_ft_label * treatment + length + unique + source + video + hashtag + daily_theme_source_count, data = df_prewar5)
m4e <- lm(ln_comments ~ theme_ft_label * treatment + length + unique + source + video + hashtag + daily_theme_source_count, data = df_prewar5)
m4f <- lm(ln_likes    ~ theme_ft_label * treatment + length + unique + source + video + hashtag + daily_theme_source_count, data = df_prewar5)

stargazer(m4a, m4b, m4c, m4d, m4e, m4f,
  type = "text",
  title = "Dependent variable: Public Engagement (Pre-May 2022, Main Narratives, Soft_propaganda as Reference)",
  se = list(robust_se(m4a), robust_se(m4b), robust_se(m4c), robust_se(m4d), robust_se(m4e), robust_se(m4f)),
  align = TRUE, star.cutoffs = c(0.05, 0.01, 0.001),
  out = "0713/table4_prewar_main5_soft.html"
)

# 6) Appendix Table 5: ALL Narratives + Sentiment (Soft ref.) ----------------
df_all_soft$sentiment_ft_factor <- df_all_soft$sentiment_ft_factor  # assumed present; no conditionals

m5a <- lm(ln_shares   ~ theme_ft_label + treatment + length + unique + source + video + hashtag + daily_theme_source_count + sentiment_ft_factor, data = df_all_soft)
m5b <- lm(ln_comments ~ theme_ft_label + treatment + length + unique + source + video + hashtag + daily_theme_source_count + sentiment_ft_factor, data = df_all_soft)
m5c <- lm(ln_likes    ~ theme_ft_label + treatment + length + unique + source + video + hashtag + daily_theme_source_count + sentiment_ft_factor, data = df_all_soft)

m5d <- lm(ln_shares   ~ theme_ft_label * treatment + length + unique + source + video + hashtag + daily_theme_source_count + sentiment_ft_factor, data = df_all_soft)
m5e <- lm(ln_comments ~ theme_ft_label * treatment + length + unique + source + video + hashtag + daily_theme_source_count + sentiment_ft_factor, data = df_all_soft)
m5f <- lm(ln_likes    ~ theme_ft_label * treatment + length + unique + source + video + hashtag + daily_theme_source_count + sentiment_ft_factor, data = df_all_soft)

stargazer(m5a, m5b, m5c, m5d, m5e, m5f,
  type = "text",
  title = "Dependent variable: Public Engagement (Soft_propaganda as Reference) + Sentiment control",
  se = list(robust_se(m5a), robust_se(m5b), robust_se(m5c), robust_se(m5d), robust_se(m5e), robust_se(m5f)),
  align = TRUE, star.cutoffs = c(0.05, 0.01, 0.001),
  out = "0713/table5_all_soft_sentiment.html"
)

# 7) Figure 1: Posts Amount change before and after the war ------------------
theme_counts_by_period <- rtweibonew %>%
  mutate(war_period = ifelse(date < as.Date("2022-02-24"), "Before War", "After War")) %>%
  count(theme_ft_label, war_period)

theme_counts_by_period$war_period <- factor(theme_counts_by_period$war_period, levels = c("Before War", "After War"))
cols <- c("Before War" = "#AED6F1", "After War" = "#4682B4")

p <- ggplot(theme_counts_by_period, 
            aes(y = theme_ft_label, x = n, fill = war_period)) +
  geom_bar(stat = "identity", 
           position = position_dodge2(preserve = "single", reverse = TRUE), 
           width = 0.7) +
  scale_fill_manual(values = cols, name = "Period") +
  theme_minimal() +
  theme(
    panel.grid.minor = element_blank(),
    panel.grid.major.y = element_blank(),
    axis.title.y = element_blank(),
    plot.title = element_text(hjust = 0.5, size = 14),
    axis.text = element_text(color = "grey40"),
    axis.title.x = element_text(size = 12),
    legend.position = "right"
  ) +
  labs(
    x = "Number of Posts"
  ) +
  scale_x_continuous(
    expand = c(0, 0),
    breaks = seq(0, max(theme_counts_by_period$n), by = 1000)
  )

ggsave("0713/Figure_1.png", p, width = 8, height = 6, dpi = 300)

# 8) Figure 2: Monthly Amount for Each Narrative -----------------------------
war_date <- as.Date("2022-02-24")
monthly_theme_counts <- rtweibonew %>%
  mutate(month = floor_date(as.Date(date), "month"),
         war_month = as.numeric((year(month) - year(war_date)) * 12 + (month(month) - month(war_date)))) %>%
  count(war_month, theme_ft_label) %>%
  filter(war_month >= -6 & war_month <= 6)

monthly_theme_counts$theme_ft_label <- factor(
  monthly_theme_counts$theme_ft_label,
  levels = c("China_news", "Other_cues", "Rotted_democracy", "Russia_achievement",
             "Russia_collaboration", "Soft_propaganda", "War", "West_hegemony")
)

all_panels <- expand_grid(
  panel_theme = levels(monthly_theme_counts$theme_ft_label),
  monthly_theme_counts
)

all_panels <- all_panels %>%
  mutate(
    highlight = ifelse(theme_ft_label == panel_theme, "highlight", "other")
  )

p <- ggplot(all_panels, aes(x = war_month, y = n, group = theme_ft_label, 
                            color = highlight, size = highlight)) +
  geom_line() +
  geom_vline(xintercept = 0, color = "red", linetype = "dashed", size = 1) +
  facet_wrap(~panel_theme, scales = "free_y", ncol = 4) +
  scale_color_manual(values = c("highlight" = "#69b3a2", "other" = "grey80")) +
  scale_size_manual(values = c("highlight" = 1.2, "other" = 0.5)) +
  labs(
    
    x = "Months from War Onset",
    y = "Number of Posts"
  ) +
  theme_ipsum() +
  theme(
    legend.position = "none",
    plot.title = element_text(size = 14, face = "bold", hjust = 0.5),
    panel.grid = element_blank(),
    strip.text = element_text(size = 10, face = "bold")
  )
ggsave("0713/Figure_2.png", p, width = 11, height = 6, dpi = 300)

# 9) Figure 5 (RD with sentiment) -------------------------------------------
run_rd <- function(df, sample_name, covars, running_var, cluster_var) {
  outcomes <- c(Shares = "ln_shares", Comments = "ln_comments", Likes = "ln_likes")
  purrr::map_dfr(outcomes, ~{
    fit <- rdrobust(df[[.x]], running_var, covs = covars, p = 1, kernel = "uniform", cluster = cluster_var)
    tibble(
      sample = sample_name,
      outcome = names(outcomes)[outcomes == .x],
      coef = fit$coef[1],
      se = fit$se[1],
      pv = fit$pv[1]
    )
  })
}

subsamples <- list(
  Rotten_democracy = RD,
  West_hegemony = WH,
  Russia_achievement = RA,
  Russia_collab = RC,
  China_news = CN,
  Soft_propaganda = SP,
  Other_cues = OC,
  War = WAR
)

covar_vars <- c("length", "unique", "source_num", "daily_theme_source_count", "video", "hashtag", "sentiment_ft_factor")

prepare_df <- function(df) {
  df %>%
    mutate(
      source_num = as.numeric(factor(source)),
      running_var = as.numeric(as.Date(date) - as.Date("2022-02-24"))
    )
}
subsamples <- purrr::map(subsamples, prepare_df)

combined_regression_table <- purrr::imap_dfr(
  subsamples,
  ~ run_rd(.x, .y, covars = .x[, covar_vars], running_var = .x$running_var, cluster_var = .x$date)
)

combined_regression_table$sample <- dplyr::recode(
  combined_regression_table$sample,
  "Russia_collab" = "Russia_collaboration",
  "Russia_collabration" = "Russia_collaboration"
)

combined_regression_table <- combined_regression_table %>%
  mutate(
    across(c(coef, se, pv), round, 3),
    signif = dplyr::case_when(
      pv < 0.001 ~ "***",
      pv < 0.01 ~ "**",
      pv < 0.05 ~ "*",
      TRUE ~ ""
    ),
    lower = coef - 1.96 * se,
    upper = coef + 1.96 * se
  ) %>%
  arrange(
    factor(
      sample,
      levels = c(
        "China_news", "West_hegemony",
        "Russia_achievement", "Rotten_democracy",
        "Soft_propaganda", "War",
        "Russia_collaboration", "Other_cues"
      )
    ),
    outcome
  )

print(combined_regression_table, n = 24)

dodge <- position_dodge(width = 0.6)

combined_regression_table$alpha <- with(
  combined_regression_table,
  ifelse(signif == "***", 1, ifelse(signif == "**", 0.75, ifelse(signif == "*", 0.5, 0.45)))
)

col_vec <- c(
  China_news = "black",
  West_hegemony = "blue",
  Russia_achievement = "red",
  Rotten_democracy = "pink",
  Soft_propaganda = "orange",
  War = "purple",
  Russia_collaboration = "green",
  Other_cues = "grey"
)

p <- ggplot(
  combined_regression_table,
  aes(y = outcome, x = coef, color = sample, fill = sample)
) +
  geom_point(shape = 21, size = 4, stroke = 1.1, color = "black", aes(alpha = alpha), position = dodge) +
  geom_point(shape = 21, size = 3, stroke = 0.8, aes(fill = sample, alpha = alpha), position = dodge) +
  geom_linerange(aes(xmin = lower, xmax = upper, alpha = alpha), position = dodge, size = 1) +
  geom_vline(xintercept = 0, linetype = "dashed", color = "grey50") +
  geom_text(aes(label = signif, x = upper), position = dodge, hjust = -0.1, size = 3.2) +
  scale_fill_manual(values = col_vec) +
  scale_color_manual(values = col_vec) +
  scale_x_continuous(breaks = seq(-2, 4, 2)) +
  guides(alpha = "none") +
  theme_minimal(base_size = 12) +
  theme(legend.title = element_blank(), plot.title = element_text(hjust = 0.5, size = 16)) +
  labs(title = "Effects of War Onset on Narrative Engagement", x = "Estimate", y = "")

ggsave("0713/rd_plot_ln_senti.png", p, width = 12, height = 8, dpi = 300)

# 10) BRICS13 (2021-06-09 ~ 2021-12-09), cutoff 2021-09-09 ------------------
robust_se <- function(model) sqrt(diag(vcovHC(model, type = "HC1")))

rtweibonew$runningBRICS13 <- as.numeric(rtweibonew$date - as.Date("2021-09-09"))
rtweibonew$BRICS13_Summit <- ifelse(rtweibonew$runningBRICS13 >= 0, 1, 0)

rtweiboBRICS13 <- rtweibonew %>%
  filter(date >= as.Date("2021-06-09") & date <= as.Date("2021-12-09")) %>%
  mutate(
    theme_ft_label = factor(
      theme_ft_label,
      levels = c(
        "Soft_propaganda", "War", "China_news", "Other_cues", "Rotted_democracy",
        "Russia_collaboration", "Russia_achievement", "West_hegemony"
      )
    )
  )

m1 <- lm(ln_shares ~ theme_ft_label + BRICS13_Summit + length + unique + sentiment_ft_factor + source + video + hashtag + daily_theme_source_count, data = rtweiboBRICS13)
m2 <- lm(ln_comments ~ theme_ft_label + BRICS13_Summit + length + unique + sentiment_ft_factor + source + video + hashtag + daily_theme_source_count, data = rtweiboBRICS13)
m3 <- lm(ln_likes ~ theme_ft_label + BRICS13_Summit + length + unique + sentiment_ft_factor + source + video + hashtag + daily_theme_source_count, data = rtweiboBRICS13)
m4 <- lm(ln_shares ~ theme_ft_label * BRICS13_Summit + length + unique + sentiment_ft_factor + source + video + hashtag + daily_theme_source_count, data = rtweiboBRICS13)
m5 <- lm(ln_comments ~ theme_ft_label * BRICS13_Summit + length + unique + sentiment_ft_factor + source + video + hashtag + daily_theme_source_count, data = rtweiboBRICS13)
m6 <- lm(ln_likes ~ theme_ft_label * BRICS13_Summit + length + unique + sentiment_ft_factor + source + video + hashtag + daily_theme_source_count, data = rtweiboBRICS13)

se_list1 <- list(robust_se(m1), robust_se(m2), robust_se(m3), robust_se(m4), robust_se(m5), robust_se(m6))

stargazer(
  m1, m2, m3, m4, m5, m6,
  type = "text",
  title = "Dependent variable: Public Engagement (BRICS13)",
  se = se_list1,
  align = TRUE,
  star.cutoffs = c(0.05, 0.01, 0.001),
  out = "0713/regressiontableBRICS13.html"
)

# 11) BRICS14 (2022-04-23 ~ 2022-08-23), cutoff 2022-06-23 ------------------
rtweibonew$runningBRICS14 <- as.numeric(rtweibonew$date - as.Date("2022-06-23"))
rtweibonew$BRICS14_Summit <- ifelse(rtweibonew$runningBRICS14 >= 0, 1, 0)

rtweiboBRICS14 <- rtweibonew %>%
  filter(date >= as.Date("2022-04-23") & date <= as.Date("2022-08-23")) %>%
  mutate(theme_ft_label = factor(theme_ft_label, 
                                 levels = c("Soft_propaganda","War","China_news","Other_cues","Rotted_democracy", 
                                            "Russia_collaboration", "Russia_achievement", "West_hegemony")))

m1_2 <- lm(ln_shares ~ theme_ft_label + BRICS14_Summit + length + unique + sentiment_ft_factor + source + video + hashtag + daily_theme_source_count, data=rtweiboBRICS14)
m2_2 <- lm(ln_comments ~ theme_ft_label + BRICS14_Summit + length + unique + sentiment_ft_factor + source + video + hashtag + daily_theme_source_count, data=rtweiboBRICS14)
m3_2 <- lm(ln_likes ~ theme_ft_label + BRICS14_Summit + length + unique + sentiment_ft_factor + source + video + hashtag + daily_theme_source_count, data=rtweiboBRICS14)
m4_2 <- lm(ln_shares ~ theme_ft_label * BRICS14_Summit + length + unique + sentiment_ft_factor + source + video + hashtag + daily_theme_source_count, data=rtweiboBRICS14)
m5_2 <- lm(ln_comments ~ theme_ft_label * BRICS14_Summit + length + unique + sentiment_ft_factor + source + video + hashtag + daily_theme_source_count, data=rtweiboBRICS14)
m6_2 <- lm(ln_likes ~ theme_ft_label * BRICS14_Summit + length + unique + sentiment_ft_factor + source + video + hashtag + daily_theme_source_count, data=rtweiboBRICS14)

se_list2 <- list(
  robust_se(m1_2), robust_se(m2_2), robust_se(m3_2),
  robust_se(m4_2), robust_se(m5_2), robust_se(m6_2)
)

stargazer(m1_2, m2_2, m3_2, m4_2, m5_2, m6_2,
          type = "text",
          title = "Dependent variable: Public Engagement (BRICS14)",
          se = se_list2,
          align = TRUE,
          star.cutoffs = c(0.05, 0.01, 0.001),
          out = "0713/regressiontableBRICS14.html"
)

# 12) Appendix A6: Baidu Index ----------------------------------------------
china_russia <- readr::read_csv("china_russia_coop.csv") %>%
  dplyr::transmute(date = as.Date(日期), count = 全部, type = "China–Russia Cooperation")

west_democracy <- readr::read_csv("west_democracy.csv") %>%
  dplyr::transmute(date = as.Date(日期), count = 全部, type = "West Democracy")

west_hegemony <- readr::read_csv("west_hegemony.csv") %>%
  dplyr::transmute(date = as.Date(日期), count = 全部, type = "West Hegemony")

df <- dplyr::bind_rows(china_russia, west_democracy, west_hegemony)

range_early <- as.Date(c("2021-08-24", "2021-11-24"))
range_late  <- as.Date(c("2022-06-24", "2022-08-24"))

df_early <- df %>% dplyr::filter(date >= range_early[1], date <= range_early[2])
df_late  <- df %>% dplyr::filter(date >= range_late[1],  date <= range_late[2])

p_main <- ggplot2::ggplot(df, ggplot2::aes(x = date, y = count, color = type, linetype = type)) +
  ggplot2::geom_line(size = 1.1) +
  ggplot2::scale_color_manual(values = c(
    "China–Russia Cooperation" = "#2976bb",
    "West Democracy" = "#de3e33",
    "West Hegemony" = "#e6b522"
  )) +
  ggplot2::scale_linetype_manual(values = c(
    "China–Russia Cooperation" = "solid",
    "West Democracy" = "dashed",
    "West Hegemony" = "dotdash"
  )) +
  ggplot2::theme_minimal(base_size = 15) +
  ggplot2::theme(
    legend.title = ggplot2::element_blank(),
    legend.position = "top",
    panel.grid.minor = ggplot2::element_blank(),
    axis.title = ggplot2::element_text(size = 14),
    axis.text = ggplot2::element_text(size = 12),
    plot.title = ggplot2::element_text(hjust = 0.5, size = 16, face = "bold")
  ) +
  ggplot2::labs(
    title = "Daily Search of Three Key Narratives",
    x = "Date",
    y = "Number of Search"
  )

p_early <- ggplot2::ggplot(df_early, ggplot2::aes(x = date, y = count, color = type, linetype = type)) +
  ggplot2::geom_line(size = 1) +
  ggplot2::scale_color_manual(values = c(
    "China–Russia Cooperation" = "#2976bb",
    "West Democracy" = "#de3e33",
    "West Hegemony" = "#e6b522"
  )) +
  ggplot2::scale_linetype_manual(values = c(
    "China–Russia Cooperation" = "solid",
    "West Democracy" = "dashed",
    "West Hegemony" = "dotdash"
  )) +
  ggplot2::theme_minimal(base_size = 11) +
  ggplot2::theme(
    legend.position = "none",
    axis.title.x = ggplot2::element_blank(),
    axis.title.y = ggplot2::element_blank(),
    plot.title = ggplot2::element_text(size = 10)
  ) +
  ggplot2::labs(title = "24 Aug to 24 Nov 2021")

p_late <- ggplot2::ggplot(df_late, ggplot2::aes(x = date, y = count, color = type, linetype = type)) +
  ggplot2::geom_line(size = 1) +
  ggplot2::scale_color_manual(values = c(
    "China–Russia Cooperation" = "#2976bb",
    "West Democracy" = "#de3e33",
    "West Hegemony" = "#e6b522"
  )) +
  ggplot2::scale_linetype_manual(values = c(
    "China–Russia Cooperation" = "solid",
    "West Democracy" = "dashed",
    "West Hegemony" = "dotdash"
  )) +
  ggplot2::theme_minimal(base_size = 11) +
  ggplot2::theme(
    legend.position = "none",
    axis.title.x = ggplot2::element_blank(),
    axis.title.y = ggplot2::element_blank(),
    plot.title = ggplot2::element_text(size = 10)
  ) +
  ggplot2::labs(title = "24 Jun to 24 Aug 2022")

inset <- cowplot::plot_grid(p_early, p_late, labels = c("A", "B"), label_size = 12, nrow = 1, rel_widths = c(1, 1))
final_plot <- cowplot::plot_grid(p_main, inset, ncol = 1, rel_heights = c(2.5, 1))

ggplot2::ggsave("0713/baidu.png", final_plot, width = 11, height = 7, dpi = 320)